package com.zzh;

import org.junit.jupiter.api.Test;

import java.util.Comparator;
import java.util.HashMap;
import java.util.TreeMap;

public class TreeMapDemo {
    public static void main(String[] args) {
     test0();
}

public static void test1() {
    TreeMap<Student,String> treeMap = new TreeMap<>(new Comparator<Student>() {
        @Override
        public int compare(Student o1, Student o2) {
            return o2.getAge() - o1.getAge();
        }
    });

    treeMap.put(new Student("张三", 18), "上海");
    treeMap.put(new Student("孙七", 22), "杭州");
    treeMap.put(new Student("周八", 23), "武汉");
    treeMap.put(new Student("吴九", 24), "西安");
    treeMap.put(new Student("郑十", 25), "南京");
    treeMap.put(new Student("王十", 26), "成都");

    treeMap.forEach((k,v)-> System.out.println(k + " " + v));
}


public static void test0() {
    TreeMap<Student, String> treeMap = new TreeMap<>();

    treeMap.put(new Student("张三", 18), "上海");
    treeMap.put(new Student("李四", 19), "北京");
    treeMap.put(new Student("王五", 20), "广州");
    treeMap.put(new Student("赵六", 21), "深圳");
    treeMap.put(new Student("郑十", 25), "南京");
    treeMap.put(new Student("王十", 26), "成都");

    treeMap.forEach((k, v) -> System.out.println(k + " " + v));


}
}